Skip to content

[None][feat] Add Gemma4 MTP assistant support#15833

Draft
lfr-0531 wants to merge 9 commits into
NVIDIA:mainfrom
lfr-0531:user/fanrongl/gemma4-mtp-support
Draft

[None][feat] Add Gemma4 MTP assistant support#15833
lfr-0531 wants to merge 9 commits into
NVIDIA:mainfrom
lfr-0531:user/fanrongl/gemma4-mtp-support

Conversation

@lfr-0531

@lfr-0531 lfr-0531 commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

@coderabbitai summary

Description

Gemma4 provides separate assistant checkpoints for multi-token prediction (MTP), but the TensorRT-LLM PyTorch backend did not recognize the assistant configuration or support running these checkpoints as a two-model speculative decoding setup.

This change adds a compatibility configuration and model implementation for Gemma4AssistantForCausalLM, including target hidden-state and embedding fusion, target KV-cache sharing, ordered/centroid-masked logits, weight mapping, and CUDA Graph-safe position handling. It also updates the two-model MTP setup to load the requested draft checkpoint, preserves all four assistant layers, avoids allocating a duplicate full-size KV cache, and forwards speculative metadata through the Gemma4 multimodal wrapper.

The changes span configuration, model execution, checkpoint loading, and executor resource setup because the assistant model needs coordinated support across those existing layers. There are no C++ changes, public API changes, or new dependencies. Existing Gemma4 execution is preserved; the new behavior is selected only for gemma4_assistant checkpoints.

Related PRs: None.

Test Coverage

  • pre-commit run --files on all ten changed files.
  • pytest -q tests/unittest/_torch/modeling/test_modeling_gemma4.py -k 'TestGemma4ModelInstantiation or TestGemma4Assistant' (15 passed).
  • Loaded and validated configuration and checkpoint structure for all four assistant checkpoints: E2B, E4B, 26B-A4B, and 31B.
  • End-to-end two-model MTP generation on B300 with the E2B target and assistant checkpoints:
    • draft length 1, CUDA Graph disabled.
    • draft length 1, CUDA Graph enabled.
    • draft length 3, CUDA Graph disabled.
    • draft length 3, CUDA Graph enabled.
  • Repeated all four end-to-end combinations after final formatting and cleanup.
  • Built and installed the native components for SM103, and verified that runtime imports used this checkout's Python sources and native bindings.

MTP Results

Each value is acceptance length / E2E speedup (batch size = 1).

Model MTP=1 MTP=2 MTP=3 MTP=4 MTP=5
Gemma4 E2B 1.6621 / 1.7908x 2.0746 / 1.7693x 2.3290 / 1.5802x 2.4854 / 2.2393x 2.5781 / 2.1387x
Gemma4 E4B 1.6859 / 1.7688x 2.1263 / 1.4682x 2.4027 / 2.2993x 2.5867 / 2.4579x 2.7120 / 2.4926x
Gemma4 26B-A4B 1.8001 / 2.0339x 2.3835 / 1.7078x 2.8068 / 2.4778x 3.0972 / 2.7620x 3.3031 / 2.6781x
Gemma4 31B 1.7978 / 1.6632x 2.3828 / 2.4062x 2.7933 / 2.7035x 3.0717 / 2.8527x 3.2644 / 3.1425x

PR Checklist

Please review the following before submitting your PR:

  • PR description clearly explains what and why. If using CodeRabbit's summary, please make sure it makes sense.

  • PR Follows TRT-LLM CODING GUIDELINES to the best of your knowledge.

  • Test cases are provided for new code paths (see test instructions)

  • If PR introduces API changes, an appropriate PR label is added - either api-compatible or api-breaking. For api-breaking, include BREAKING in the PR title.

  • Any new dependencies have been scanned for license and vulnerabilities

  • CODEOWNERS updated if ownership changes

  • Documentation updated as needed

  • Update tava architecture diagram if there is a significant design change in PR.

  • The reviewers assigned automatically/manually are appropriate for the PR.

  • Please check this after reviewing the above items as appropriate for this PR.

GitHub Bot Help

To see a list of available CI bot commands, please comment /bot help.

@lfr-0531

lfr-0531 commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #56933 [ run ] triggered by Bot. Commit: 346825e Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #56933 [ run ] completed with state SUCCESS. Commit: 346825e
/LLM/main/L0_MergeRequest_PR pipeline #45738 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@lfr-0531
lfr-0531 force-pushed the user/fanrongl/gemma4-mtp-support branch from 346825e to 49e054e Compare July 2, 2026 15:03
@lfr-0531

lfr-0531 commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #57206 [ run ] triggered by Bot. Commit: a49a1ba Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #57206 [ run ] completed with state FAILURE. Commit: a49a1ba
/LLM/main/L0_MergeRequest_PR pipeline #45977 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@lfr-0531
lfr-0531 force-pushed the user/fanrongl/gemma4-mtp-support branch 2 times, most recently from ca4cd19 to 4b170de Compare July 7, 2026 01:56
@lfr-0531
lfr-0531 force-pushed the user/fanrongl/gemma4-mtp-support branch from 4b170de to c250ca1 Compare July 21, 2026 15:37
@lfr-0531

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #60734 [ run ] triggered by Bot. Commit: e132e69 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #60734 [ run ] completed with state FAILURE. Commit: e132e69
/LLM/main/L0_MergeRequest_PR pipeline #49021 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

lfr-0531 added 8 commits July 22, 2026 05:56
Add standalone Gemma4 assistant config, model, weight loading, and target KV-cache sharing for two-model MTP decoding. Support masked assistant logits and CUDA graph execution, and add structural coverage for assistant configuration and KV source mapping.

Signed-off-by: Fanrong Li <23290157+lfr-0531@users.noreply.github.com>
Signed-off-by: Fanrong Li <23290157+lfr-0531@users.noreply.github.com>
Signed-off-by: Fanrong Li <23290157+lfr-0531@users.noreply.github.com>
Signed-off-by: Fanrong Li <23290157+lfr-0531@users.noreply.github.com>
Signed-off-by: Fanrong Li <23290157+lfr-0531@users.noreply.github.com>
Preserve Gemma4 assistant hidden-state and position semantics across
multi-token drafting, and capture target hidden states for verification.
Refresh FlashInfer paged-prefill graph state after request turnover and
add regression coverage for drafting and CUDA graph replay.

Signed-off-by: Fanrong Li <23290157+lfr-0531@users.noreply.github.com>
Normalize the Gemma4 assistant CUDA graph key across capture and runtime
lookup so the full drafting loop replays its captured graph instead of
silently falling back to eager execution. Add regression coverage for the
first-draft state transition.

Signed-off-by: Fanrong Li <23290157+lfr-0531@users.noreply.github.com>
Reuse the existing linear drafting loop through model capabilities, enforce assistant configuration invariants, and reject unsupported shared-KV combinations.\n\nFix vocab-parallel ordered logits, shared target KV cache ownership and budgeting, CUDA graph capacity, and FlashInfer KV pool identity. Add focused regressions for configuration, TP logits, graph sizing, cache budgets, and same-head-dimension pools.

Signed-off-by: Fanrong Li <23290157+lfr-0531@users.noreply.github.com>
@lfr-0531
lfr-0531 force-pushed the user/fanrongl/gemma4-mtp-support branch from e132e69 to 925108f Compare July 22, 2026 15:48
@lfr-0531

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61013 [ run ] triggered by Bot. Commit: 925108f Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61013 [ run ] completed with state FAILURE. Commit: 925108f
/LLM/main/L0_MergeRequest_PR pipeline #49269 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

Signed-off-by: Fanrong Li <23290157+lfr-0531@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants